const path = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin');
const copyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    //入口文件
    entry: path.resolve(__dirname, "../src/index.js"),

    //出口文件
    output: {
        path: path.resolve(__dirname, "../build"),
        filename: "./js/main.js",
        publicPath: "/"
    },

    //插件配置
    plugins: [
        new htmlWebpackPlugin({
            template: path.resolve(__dirname, "../public/index.html"),
            filename: "./index.html"
        }),
        new copyWebpackPlugin({
            patterns: [{
                from: path.resolve(__dirname, "../public"),
                to: "./public",
                globOptions: {
                    ignore: ["**/index.html"]
                }
            }],
        })
    ],

    //loader的配置
    module: {
        rules: [
            //ejs的loader
            {
                test: /\.ejs$/i,
                loader: 'ejs-loader',
                options: {
                    variable: 'data',
                }
            },
            //css的loader
            {
                test: /\.css$/i,
                use: [
                    //use中loader加载是有顺序的，先下后上，注意有的loader需要按照顺序书写
                    "style-loader",
                    'css-loader'
                ]
            },
        ]
    },

    //配置别名
    resolve: {
        alias: {
            $v: path.resolve(__dirname, "../src/views")
        },
        extensions: [".js", ".json", ".ejs"],
    },

    //模式
    mode: "production"
}